package com.indexingsystem.system.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.indexingsystem.boss.Vo.StatusList;
import com.indexingsystem.boss.Vo.SysConfigVo;
import com.indexingsystem.boss.admin.mapper.SysConfigMapper;
import com.indexingsystem.boss.common.PagedResult;
import com.indexingsystem.boss.entity.SysConfig;
import com.indexingsystem.boss.utils.BeanUtils;
import com.indexingsystem.system.service.ISysConfigService;

@Service
public class SysConfigServiceImpl implements ISysConfigService {

	@Resource
	private SysConfigMapper sysConfigMapper;

	@Override
	public int deleteByPrimaryKey(String sysConfigId) {
		return sysConfigMapper.deleteByPrimaryKey(sysConfigId);
	}

	/**
	 * 批量删除系统配置.
	 * 
	 * @param sysConfigIdList
	 * @return
	 */
	@Override
	public int deleteSysConfigByIdBatch(List<String> sysConfigIdList) {
		return sysConfigMapper.deleteSysConfigByIdBatch(sysConfigIdList);
	}

	@Override
	public int insertSelective(SysConfig record) {
		return sysConfigMapper.insertSelective(record);
	}

	@Override
	public SysConfig selectByPrimaryKey(String sysConfigId) {
		return sysConfigMapper.selectByPrimaryKey(sysConfigId);
	}

	@Override
	public int updateByPrimaryKeySelective(SysConfig record) {
		return sysConfigMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public PagedResult<SysConfig> selectSysConfigList(String queryCriteria,Integer pageNo, Integer pageSize) {
		pageNo = pageNo == null ? 1 : pageNo;
		pageSize = pageSize == null ? 10 : pageSize;
		// startPage是告诉拦截器说我要开始分页了。分页参数是这两个。
		PageHelper.startPage(pageNo, pageSize);
		return BeanUtils.toPagedResult(sysConfigMapper.selectSysConfigList(queryCriteria));
	}

	/**
	 * 获取基础配置信息总数量.
	 */
	@Override
	public Integer getSysConfigListCount(String queryCriteria) {
		return sysConfigMapper.getSysConfigListCount(queryCriteria);
	}

	/**
	 * 通过key查询基础配置.
	 */
	@Override
	public List<SysConfig> getSysConfigByKey(String key) {
		return sysConfigMapper.getSysConfigByKey(key);
	}

	/**
	 * 通过系统参数键和参数值查询是否已存在重复.
	 * 
	 * @param sysConfig
	 * @return
	 */
	@Override
	public SysConfig getSysConfigByKeyOrValue(SysConfigVo sysConfig) {
		return sysConfigMapper.getSysConfigByKeyOrValue(sysConfig);
	}
	
	/**
	 * 通过系统参数键和名称查询是否已存在重复.
	 * 
	 * @param sysConfig
	 * @return
	 */
	@Override
	public SysConfig getSysConfigByKeyOrName(SysConfigVo sysConfig) {
		return sysConfigMapper.getSysConfigByKeyOrName(sysConfig);
	}

	/**
	 * 批量启用，禁用权限.
	 * 
	 * @param operationMap
	 * @return
	 */
	@Override
	public int batchUpdateSysConfigWithList(List<StatusList> list) {
		return sysConfigMapper.batchUpdateSysConfigWithList(list);
	}
	
	   /**
     * 通过系统参数值和参数名称查询是否已存在重复.
     * @param sysVonfig
     * @return
     */
	@Override
    public SysConfig getSysConfigByValueOrName(SysConfigVo sysConfig){
        return sysConfigMapper.getSysConfigByValueOrName(sysConfig);
    }
}